using RabbitMQ.Client;

namespace Aurora.RabbitMq.Provider;

/// <summary>
/// rabbit mq connections
/// </summary>
[Serializable]
public class RabbitMqConnections : Dictionary<string, ConnectionFactory>
{
    public ConnectionFactory Default
    {
        get => this[RabbitMqConst.DefaultConnectionName];
        set
        {
            ArgumentNullException.ThrowIfNull(value);
            Add(RabbitMqConst.DefaultConnectionName, value);
        }
    }

    public RabbitMqConnections()
    {
        Default = new ConnectionFactory();
    }

    public ConnectionFactory GetOrDefault(string connectionName)
    {
        return TryGetValue(connectionName, out var connectionFactory) ? connectionFactory : Default;
    }
}